﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Demos.Threads.Models;

namespace Demos.Threads.Services
{
    public class UserService : IUserService
    {

        List<UserInfoDto> list = new List<UserInfoDto> ();

        public UserService()
        {
            list.Add(new UserInfoDto(Guid.Parse("817ec66f-8afe-4c98-a71f-426c39d830d9"), "zhangsan", "zhangsan@sing.com"));
            list.Add(new UserInfoDto(Guid.Parse("a45b4753-0a25-4f16-a3e5-3c42b754d34f"), "zhangsan1", "zhangsan1@sing.com"));
            list.Add(new UserInfoDto(Guid.NewGuid(), "zhangsan2", "zhangsan2@sing.com"));
            list.Add(new UserInfoDto(Guid.NewGuid(), "zhangsan3", "zhangsan3@sing.com"));
        }

        public List<UserInfoDto> GetList()
        {
            return list;
        }


        public UserInfoDto GetUser(Guid id)
        {
            return list.Where(it => it.Id == id).FirstOrDefault();
        }

        public UserInfoDto GetUserByName(string name)
        {
            return list.Where(it => it.Name == name).FirstOrDefault();
        }

        public UserInfoDto AddUser(UserInfoDto dto)
        {
            list.Add(new UserInfoDto(dto.Id, dto.Name, dto.Email));

            return list.FirstOrDefault(it => it.Id == dto.Id);
        }
    }
}
